/**
 * @(#)TestSystemLoginAction.java Nov 19, 2009
 *   
 * Copyright  (c) 2009-2010 Wilmar IT Service,  Inc.   
 * All  rights  reserved.   
 * TODO
 */

package test.system.web.actions;

import java.util.HashSet;
import java.util.Set;

import com.wilmar.process.entity.Organization;
import com.wilmar.process.entity.Role;
import com.wilmar.process.entity.User;
import com.wilmar.process.exception.DirtyDataException;
import com.wilmar.process.web.actions.ProcessActionSupport;

/**
 * @author makubex Email:makubexnet@gmail.com
 * @version 1.0.0
 */
public class SimpleSystemLoginAction extends ProcessActionSupport {

	/**
	 * @serialField
	 */
	private static final long serialVersionUID = 3884861280887092943L;

	private String userName;
	private String userEmail;
	private String userRole;
	private String userOrg;
	
	public String doGotoIndex(){
		return SUCCESS;
	}

	public String doLogin() {
		System.out.println("Doing Logining......");
		try {
			User currentUser = new User("wsp-user-" + userName);
			currentUser.setEmail(userEmail);
			currentUser.setName(userName);
			super.session.put("currentuser", currentUser);

			String[] s_role = userRole.split(",");
			Set<Role> roleSet = new HashSet<Role>();
			for (String role : s_role) {
				Role r = new Role("wsp-role-" + role);
				r.setRoleName(role);
				roleSet.add(r);
			}
			super.session.put("currentrole", roleSet);

			String[] s_org = userOrg.split(",");
			Set<Organization> orgSet = new HashSet<Organization>();
			for (String org : s_org) {
				Organization o = new Organization("wsp-organization-" + org);
				o.setOrganizationName(org);
				orgSet.add(o);
			}
			super.session.put("currentorg", orgSet);

		} catch (DirtyDataException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	/**
	 * @return the userName
	 */
	public String getUserName() {
		return userName;
	}

	/**
	 * @param userName
	 *            the userName to set
	 */
	public void setUserName(String userName) {
		this.userName = userName;
	}

	/**
	 * @return the userEmail
	 */
	public String getUserEmail() {
		return userEmail;
	}

	/**
	 * @param userEmail
	 *            the userEmail to set
	 */
	public void setUserEmail(String userEmail) {
		this.userEmail = userEmail;
	}

	/**
	 * @return the userRole
	 */
	public String getUserRole() {
		return userRole;
	}

	/**
	 * @param userRole
	 *            the userRole to set
	 */
	public void setUserRole(String userRole) {
		this.userRole = userRole;
	}

	/**
	 * @return the userOrg
	 */
	public String getUserOrg() {
		return userOrg;
	}

	/**
	 * @param userOrg
	 *            the userOrg to set
	 */
	public void setUserOrg(String userOrg) {
		this.userOrg = userOrg;
	}
}
